/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 杨已萱
 * Date: 2023-04-11
 * Time: 21:44
 */

    class Solution {
        public int countSegments(String s) {
            int segmentCount = 0;

            for (int i = 0; i < s.length(); i++) {
                if ((i == 0 || s.charAt(i - 1) == ' ') && s.charAt(i) != ' ') {
                    segmentCount++;
                }
            }

            return segmentCount;
        }
    }


